<template>
	<view class="content">
		<view class="group-title">收款信息</view>
		<u-field label-width="150" name="wx" v-model="alipay.wx" label="微信账号" placeholder="请输入微信账号">
		</u-field>
		<u-field label-width="150" name="realname" v-model="alipay.realname" label="真实姓名" placeholder="请输入真实姓名">
		</u-field>
		<!-- <u-field label-width="150" name="alipay" v-model="alipay.alipay" label="支付宝账号" placeholder="请输入支付宝账号">
		</u-field> -->
		<u-field label-width="150" name="alipay" v-model="alipay.alipay" label="支付宝账号" placeholder="请输入支付宝账号">
		</u-field>
		<u-field label-width="150" name="alipay_name" v-model="alipay.alipay_name" label="账号姓名" placeholder="请输入支付宝账号姓名">
		</u-field>
		<view class="group-title">银行卡信息</view>
		<u-field @click.native="$Router.push('/pages/prefile/bank-detail/bank-detail')" right-icon="arrow-right"
			:disabled="true" label-width="150" name="bank_name" v-model="userForm.bank_name" label="银行卡">
		</u-field>
		<view style="margin: 80upx 45upx;">
			<u-button style="" @click="formSubmit" type="error">提交</u-button>
		</view>
	</view>
</template>

<script>
	import WxValidate from '@/common/utils/WxValidate.js'
	export default {
		data() {
			return {
				alipay: {
					"wx": "", //微信号
					"realname": "", //真实姓名
					"alipay": '', //支付宝账号
					"alipay_name": '', //支付宝姓名
				},
				userForm: {
					bank_name: ''
				}
			};
		},
		onLoad() {
			this.initValidate();
			
		},
		onShow() {
			this.getSetingali();
		},
		methods: {
			// 获取支付宝信息
			getSetingali() {
				this.$api.get('/addons/yun_shop/api.php?route=member.member.xgetUser&ingress=weChatApplet&validate_page=1&app_type=wechat').then(res => {
					this.alipay = Object.assign({}, this.alipay , res.data);
				})
			},
			// 初始化验证规则
			initValidate() {
				const rules = {
					alipay: {
						required: true
					},
					alipay_name: {
						required: true
					},
				}
				const messages = {
					alipay: {
						required: "请输入支付宝账号"
					},
					alipay_name: {
						required: "请输入支付宝姓名"
					},
					
				}
				this.WxValidate = new WxValidate(rules, messages)
			},
			//验证信息弹出
			showModal(error) {
				uni.showToast({
					title: error.msg,
					icon: "none"
				})
			},
			// 提交验证
			formSubmit() {
				if (!this.WxValidate.checkForm(this.alipay)) { //获取表单信息进行验证
					this.showModal(this.WxValidate.errorList[0])
					return false
				}
				this.actionSetingali();
			},
			// 绑定支付宝
			actionSetingali(){
				this.$api.post('/addons/yun_shop/api.php?route=member.member.updateUserInfo&ingress=weChatApplet&validate_page=1&app_type=wechat', {data:this.alipay}).then(res => {
					uni.showToast({
						title: res.msg
					})
				})
			}
		},
		
	}
</script>

<style scoped lang="scss">
	@import './bank-list.scss';
</style>
